﻿#region | Copyright © Siriwat Suananpornpanit 2556 |

/*
	##########################################################################
		Software Generator Code For Hashtable From Table Name => MST_BUYER_GROUP
		Author By : Siriwat Suananpornpanit
		DateTime : 2556/08/22 12:03:20
	##########################################################################
	*/

#endregion

#region Class | Imports |

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using DataAccess.Interface;
using Microsoft.VisualBasic;
using System.Text;
using DataAccess.DBConnections;
using DataAccess.ProxyConnections;
using Oracle.DataAccess.Client;

#endregion

namespace DataAccess.Dal
{
    internal class MstBuyerGroupDal //: IResponsible<Prop.MstBuyerGroup>
    {

        /* for DataBase Connection */

        private static DBConnectionsEngine dbEngine;

        private static OracleConnection Conn;

        private static Hashtable hashtable;


        private static MstBuyerGroupDal _dal;

        private System.String sql = "";


        public static MstBuyerGroupDal GetInstance()
        {
            /* for Init */

            dbEngine = new DBConnectionsEngine();

            Conn = new DatabaseProxy().GetAuthConnection();

            _dal = new MstBuyerGroupDal();

            return _dal;
        }

        public IEnumerable<Prop.MstBuyerGroup> Select(Prop.MstBuyerGroup obj)
        {
            IEnumerable<Prop.MstBuyerGroup> entities = new List<Prop.MstBuyerGroup>();
            try
            {
                System.Text.StringBuilder concast = new System.Text.StringBuilder();

                concast.Append(" WHERE 1=1 ");

                hashtable = new Hashtable();

                if (obj != null)
                {
                    if (!String.IsNullOrEmpty(obj.EMPNO))
                    {
                        concast.Append(" AND EMPNO=:EMPNO ");
                        hashtable.Add(":EMPNO", obj.EMPNO);
                    }

                    if (!String.IsNullOrEmpty(obj.APPLNO))
                    {
                        concast.Append(" AND APPLNO=:APPLNO ");
                        hashtable.Add(":APPLNO", obj.APPLNO);
                    }

                    if (!String.IsNullOrEmpty(obj.BUYER_GROUP))
                    {
                        concast.Append(" AND BUYER_GROUP=:BUYER_GROUP ");
                        hashtable.Add(":BUYER_GROUP", obj.BUYER_GROUP);
                    }

                    if (!Information.IsDate(obj.CRDATE))
                    {
                        concast.Append(" AND CRDATE=:CRDATE ");
                        hashtable.Add(":CRDATE", obj.CRDATE);
                    }

                    if (!String.IsNullOrEmpty(obj.COMPANY_CODE))
                    {
                        concast.Append(" AND COMPANY_CODE=:COMPANY_CODE ");
                        hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                    }

                }
                sql = System.String.Format(@" SELECT EMPNO ,APPLNO ,BUYER_GROUP ,CRDATE ,COMPANY_CODE  FROM MST_BUYER_GROUP");

                sql = sql + concast.ToString();

                entities = dbEngine.ToList<Prop.MstBuyerGroup>(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                entities = null;
            }
            return entities;
        }

        public bool Add(Prop.MstBuyerGroup obj)
        {
            Boolean result = false;
            try
            {
                sql = System.String.Format(@" INSERT INTO MST_BUYER_GROUP(EMPNO ,APPLNO ,BUYER_GROUP ,CRDATE ,COMPANY_CODE )
					VALUES(:EMPNO ,:APPLNO ,:BUYER_GROUP ,:CRDATE ,:COMPANY_CODE ");

                hashtable = new Hashtable();
                hashtable.Add(":EMPNO", obj.EMPNO);
                hashtable.Add(":APPLNO", obj.APPLNO);
                hashtable.Add(":BUYER_GROUP", obj.BUYER_GROUP);
                hashtable.Add(":CRDATE", obj.CRDATE);
                hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                dbEngine.ExecuteNonQuery(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                result = true;
            }
            return result;
        }

        public bool Update(Prop.MstBuyerGroup obj)
        {
            Boolean result = false;
            try
            {
                sql = System.String.Format(@" UPDATE MST_BUYER_GROUP
					SET
					EMPNO=:EMPNO,
					APPLNO=:APPLNO,
					BUYER_GROUP=:BUYER_GROUP,
					CRDATE=:CRDATE,
					COMPANY_CODE=:COMPANY_CODE");

                hashtable = new Hashtable();
                hashtable.Add(":EMPNO", obj.EMPNO);
                hashtable.Add(":APPLNO", obj.APPLNO);
                hashtable.Add(":BUYER_GROUP", obj.BUYER_GROUP);
                hashtable.Add(":CRDATE", obj.CRDATE);
                hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);

                dbEngine.ExecuteNonQuery(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                result = true;
            }
            return result;
        }

        public bool Delete(Prop.MstBuyerGroup obj)
        {
            Boolean result = false;
            try
            {

                System.Text.StringBuilder concast = new System.Text.StringBuilder();

                concast.Append(" WHERE 1=1 ");

                hashtable = new Hashtable();

                if (obj != null)
                {
                    if (!String.IsNullOrEmpty(obj.EMPNO))
                    {
                        concast.Append(" AND EMPNO=:EMPNO ");
                        hashtable.Add(":EMPNO", obj.EMPNO);
                    }

                    if (!String.IsNullOrEmpty(obj.APPLNO))
                    {
                        concast.Append(" AND APPLNO=:APPLNO ");
                        hashtable.Add(":APPLNO", obj.APPLNO);
                    }

                    if (!String.IsNullOrEmpty(obj.BUYER_GROUP))
                    {
                        concast.Append(" AND BUYER_GROUP=:BUYER_GROUP ");
                        hashtable.Add(":BUYER_GROUP", obj.BUYER_GROUP);
                    }

                    if (!Information.IsDate(obj.CRDATE))
                    {
                        concast.Append(" AND CRDATE=:CRDATE ");
                        hashtable.Add(":CRDATE", obj.CRDATE);
                    }

                    if (!String.IsNullOrEmpty(obj.COMPANY_CODE))
                    {
                        concast.Append(" AND COMPANY_CODE=:COMPANY_CODE ");
                        hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                    }

                }
                sql = System.String.Format(@" DELETE FROM MST_BUYER_GROUP ");

                sql = sql + concast.ToString();

                dbEngine.ExecuteNonQuery(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                result = true;
            }
            return result;
        }

    }
}

/*
##########################################################################
    Free Software License
##########################################################################
*/

